﻿#pragma once
#include<assert.h>
#include<stdio.h>
#include<iostream>

using namespace std;
namespace jz
{
	class string {
	public:


		typedef char* iterator;
		typedef const char* const_iterator;

		iterator begin()
		{
			return m_str;
		}

		iterator end()
		{
			return m_str + m_size;
		}

		const_iterator begin() const
		{
			return m_str;
		}

		const_iterator end() const
		{
			return m_str + m_size;
		}

		const char* c_str() const
		{
			return m_str;
		}

		size_t size() const
		{
			return m_size;
		}

		string(const char* str = "");
		// 
		string(const string& s);
		string& operator=(string s);
		~string();

		const char& operator[](size_t pos) const;
		char& operator[](size_t pos);
		void reserve(size_t n);
		void push_back(char ch);

		void append(const char* str);
		string& operator+=(char ch);
		string& operator+=(const char* str);

		void insert(size_t pos, char ch);
		void insert(size_t pos, const char* str);
		void erase(size_t pos, size_t len = npos);
		void swap(string& s);
		size_t find(char ch, size_t pos = 0);
		//21:10
		size_t find(const char* str, size_t pos = 0);
		string substr(size_t pos = 0, size_t len = npos);
		void clear();	
	private:
		char* m_str;
		size_t m_size;
		size_t m_capacity;
		const static size_t npos = -1;
	};
	ostream& operator<<(ostream& out, const string& s);
	istream& operator>>(istream& in, string& s);
	void test();
}

